<?php
namespace Home\Controller;
use Think\Controller;
/**
 * Class ArticleController
 * @package Admin\Controller
 * 2017-12-13   留言类
 */
class MessageController extends AdminBasicController{

    public $message = '';
    public $shop_id;
    public function _initialize(){
        $this->checkLogin();
        $this->message = D('Message');
        $this->shop_id = session('SHOP_ID');
    }

    /**
     * 留言列表
     * @author mss
     * @time 2017-12-14
     */
    public function messageList(){
        $where = array();
        $param = array();
        $where['status'] = 0;
        $where['shop_id'] = $this->shop_id;
        $order = 'ctime DESC';
        /**按姓名或手机号搜索*/
        if(!empty(trim(I('request.name')))){
            $name = trim(I('request.name'));
            $where['name|phone'] = array('LIKE','%'.$name.'%');
            $param['name'] = $name;
        }

        /**按发布时间查找*/
        if(!empty(I('request.start_time')) && !empty(I('request.end_time'))){
            $start_time = I('request.start_time');
            $this->assign("start_time",$start_time);
            $end_time = I('request.end_time');
            $this->assign("end_time",$end_time);
            $where['ctime'] = array(array('EGT',strtotime($start_time)),array('ELT',strtotime($end_time)),'and');
            $parameter['start_time'] = I('request.start_time');
            $parameter['end_time'] = I('request.end_time');
        }

        $list = $this->message->selectMessage($where,$order,15,$param);
        $data = $list['list'];

        $this->assign('list',$data);
        $this->assign('page',$list['page']);
        $this->assign('request',$_REQUEST);

        $this->display('messageList');
    }

    /**
     * 删除留言
     * @author mss
     * @time 2017-12-14
     */
    public function delMessage(){
        if(empty($_REQUEST['msg_id'])){
            $this->error('您未选择任何操作对象');
        }
        $where['msg_id'] = array('IN',I('request.msg_id'));
        $data['status'] = 9;
        $data['utime'] = time();
        $upd_res = $this->message->editMessage($where,$data);
        if($upd_res){
            //其他删除操作

            $this->success('删除操作成功');
        }else{
            $this->error('删除操作失败');
        }
    }

}